﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Utility.Events;

namespace TimeTracker.EditForms
{
    public partial class EditNote : Form
    {
        protected INote note
        {
            get;
            private set;
        }

        public EditNote(INote note)
        {
            this.note = note;

            InitializeComponent();

            if (this.note.Session != null)
            {
                this.note1.MinTime = this.note.Session.StartTime;
                if (this.note.Session.EndTime.HasValue)
                {
                    this.note1.MaxTime = this.note.Session.EndTime.Value;
                }
            }
            this.note1.Time = note.Time;
            this.note1.Text = note.Text;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.note.Time = this.note1.Time;
            this.note.Text = this.note1.Text;

            Manager.Instance.Save();

            this.Saved.Fire(sender, this.note);

            this.Close();
        }

        public event EventHandler<EventArgs<INote>> Saved;
    }
}
